﻿/// <reference path="jquery-1.9.1.min.js" />

if (window.controls == null) window.controls = {};
window.controls.Calendar = function (_inputControlID, _needTimes) {
    var Me = this;
    var acts = {};
    var TBOX = $('#' + _inputControlID);
    var NeedTimes = _needTimes == null ? true : _needTimes;
    var time = " 00:00:00";
    time = "";
    var args = {
        controlId: _inputControlID + "CalendarDiv",
        speed: 400,
        complement: true,
        readonly: ($(TBOX).attr['readonly'] == 'readonly' || $(TBOX).attr['readonly'] == 'true') ? true : false,
        dateUpperLimit: NaN,
        dateLowerLimit: NaN,
        inputTime: true,
        callback: function () { }
    }
    acts.Init = function () {
        if (NeedTimes) {
            acts.AddTimeDropList();
        }
        acts.Constructor();
        acts.EventBind();
        delete acts.Init;
    }
    acts.SetDays = function setDays() {
        $("#" + args.controlId).find(".tabD a").mouseup(function () {
            var text = $("#" + args.controlId).find(".currentText").text();
            var y = Number(text.substring(0, text.indexOf('\u5e74')));
            var m = Number(text.substring(text.indexOf('\u5e74') + 1, text.indexOf('\u6708')));
            var a = new Date(y + "/" + m + "/1");
            if ($(this).hasClass("prevD")) {
                a.setMonth(a.getMonth() - 1);
                a.setDate($(this).text());
                var b = args.speed;
                args.speed = 0;
                $("#" + args.controlId).find(".prev").triggerHandler("mouseup");
                args.speed = b;
            } else if ($(this).hasClass("nextD")) {
                a.setMonth(a.getMonth() + 1);
                a.setDate($(this).text());
                b = args.speed;
                args.speed = 0;
                $("#" + args.controlId).find(".next").triggerHandler("mouseup");
                args.speed = b;
            }
            var d = $(this).text();
            a = a.getFullYear() + "-" + (Number(a.getMonth() + 1) < 10 ? "0" + Number(a.getMonth() + 1) : Number(a.getMonth() + 1)) + "-" + (Number(d) < 10 ? "0" + d : d);
            if (args.inputTime) {
                if (NeedTimes) {
                    time = acts.GetHMS();
                    TBOX.val(a + " " + time);
                }
                else {
                    TBOX.val(a);
                }
            }
            else {
                TBOX.val(a);
            }
            $("#" + args.controlId + " div table a").removeClass("select");
            $("#" + args.controlId + " .tabD a:contains('" + d + "')").each(function () {
                d == $(this).text() && !$(this).hasClass("prevD") && !$(this).hasClass("nextD") && $(this).addClass("select");
            });
            $("#" + args.controlId).hide();
            args.callback();
        }).hover(function () {
            $(this).addClass("hover");
        },
		function () {
		    $(this).removeClass("hover");
		})
    }
    acts.SetMonths = function setMonths() {
        $("#" + args.controlId).find(".tabM a").mouseup(function () {
            var y = Number($("#" + args.controlId).find(".currentText").text());
            var m = Number($(this).attr("val"));
            var a = acts.GetDays(y, m);
            acts.SelectedYearOrMonth(a);
            acts.SetDays();
            $("#" + args.controlId).find(".currentText").text(y + '\u5e74' + (m + 1) + '\u6708')
        }).hover(function () {
            $(this).addClass("hover")
        },
		function () {
		    $(this).removeClass("hover")
		});
    }
    acts.SetYears = function setYears() {
        $("#" + args.controlId).find(".tabY a").mouseup(function () {
            var y = Number($(this).text());
            var a = acts.GetMonths(y);
            acts.SelectedYearOrMonth(a);
            acts.SetMonths();
            $("#" + args.controlId).find(".currentText").text(y)
        }).hover(function () {
            $(this).addClass("hover");
        },
		function () {
		    $(this).removeClass("hover");
		});
    }
    acts.SetYearsRange = function setYearsRange() {
        $("#" + args.controlId).find(".tabYS a").mouseup(function () {
            var y = Number($(this).text().substring(0, $(this).text().indexOf('-')));
            var a = acts.GetYears(y);
            acts.SelectedYearOrMonth(a);
            acts.SetYears();
            $("#" + args.controlId).find(".currentText").text($(this).text())
        }).hover(function () {
            $(this).addClass("hover");
        },
		function () {
		    $(this).removeClass("hover");
		});
    }
    acts.GetDays = function getDays(a, b) {
        var today = new Date;
        var e = today.getFullYear();
        var f = today.getMonth();
        var q = today.getDate();
        newDate = new Date(a, b, 1);
        newDate.setDate(0);
        var d = 1;
        var h = newDate.getDate();
        newDate.setDate(1);
        newDate.setMonth(newDate.getMonth() + 1);
        var m = newDate.getDay();
        if (m == 0) m = 7;
        h = h - m + 1;
        newDate.setMonth(newDate.getMonth() + 1);
        newDate.setDate(0);
        var o = newDate.getDate();
        var g = "<table class='tabD'>";
        g += "<tr>";
        g += "<th>\u65e5</th>";
        g += "<th>\u4e00</th>";
        g += "<th>\u4e8c</th>";
        g += "<th>\u4e09</th>";
        g += "<th>\u56db</th>";
        g += "<th>\u4e94</th>";
        g += "<th>\u516d</th>";
        g += "</tr>";
        var i = acts.FormatInputValue();
        var l = "";
        var p = "";
        var t = "";
        args.complement || (t = "style='display:none'");
        for (var x = 0; x < 6; x++) {
            g += "<tr>";
            for (var y = 0; y < 7; y++) {
                var j = x * 7 + y + 1 - m;
                p = l = "";
                if (args.dateLowerLimit != NaN && args.dateLowerLimit > new Date(newDate.getFullYear(), newDate.getMonth(), j) || args.dateUpperLimit != NaN && new Date(newDate.getFullYear(), newDate.getMonth(), j) > args.dateUpperLimit) {
                    if (0 < j && j <= o) {
                        if (newDate.getFullYear() == e && newDate.getMonth() == f && j == q) {
                            l = "current";
                        }
                        g += "<td><span class='" + l + "'>" + j + "</span></td>";
                    }
                    else if (j <= 0) {
                        if (newDate.getFullYear() == e && newDate.getMonth() - 1 == f && h == q) {
                            l = "current";
                        }
                        g += "<td><span class='" + l + "' " + t + ">" + h + "</span></td>";
                        h++;
                    }
                    else {
                        if (j > o) {
                            if (newDate.getFullYear() == e && newDate.getMonth() + 1 == f && d == q) {
                                l = "current";
                            }
                            g += "<td><span class='" + l + "' " + t + ">" + d + "</span></td>";
                            d++;
                        }
                    }
                }
                else if (0 < j && j <= o) {
                    if (newDate.getFullYear() == e && newDate.getMonth() == f && j == q) {
                        l = "current";
                    }
                    if (newDate.getFullYear() == i.getFullYear() && newDate.getMonth() == i.getMonth() && j == i.getDate()) {
                        p = "select";
                    }
                    g += "<td><a class='" + p + " " + l + "'>" + j + "</a></td>";
                }
                else if (j <= 0) {
                    if (newDate.getFullYear() == e && newDate.getMonth() - 1 == f && h == q) {
                        l = "current";
                    }
                    if (newDate.getFullYear() == i.getFullYear() && newDate.getMonth() - 1 == i.getMonth() && h == i.getDate()) {
                        p = "select";
                    }
                    g += "<td><a class='prevD " + p + " " + l + "' " + t + ">" + h + "</a></td>";
                    h++;
                }
                else if (j > o) {
                    if (newDate.getFullYear() == e && newDate.getMonth() + 1 == f && d == q) {
                        l = "current";
                    }
                    if (newDate.getFullYear() == i.getFullYear() && newDate.getMonth() + 1 == i.getMonth() && d == i.getDate()) {
                        p = "select";
                    }
                    g += "<td><a class='nextD " + p + " " + l + "' " + t + ">" + d + "</a></td>";
                    d++;
                }
                g = g.replace("class=' '", "")
            }
            g += "</tr>"
        }
        g += "</table>";
        return g;
    }
    acts.GetMonths = function getMonths(a) {
        var today = new Date;
        var e = today.getFullYear();
        var f = today.getMonth();
        var q = today.getDate();
        var b = acts.FormatInputValue();
        var d = "<table class='tabM'>";
        d += "<tr>";
        d += "<td><a val='0' " + (a == b.getFullYear() && 0 == b.getMonth() ? "class='select'" : "") + " " + (a == e && 0 == f ? "class='current'" : "") + ">\u4e00\u6708</a></td>";
        d += "<td><a val='1' " + (a == b.getFullYear() && 1 == b.getMonth() ? "class='select'" : "") + " " + (a == e && 1 == f ? "class='current'" : "") + ">\u4e8c\u6708</a></td>";
        d += "<td><a val='2' " + (a == b.getFullYear() && 2 == b.getMonth() ? "class='select'" : "") + " " + (a == e && 2 == f ? "class='current'" : "") + ">\u4e09\u6708</a></td>";
        d += "<td><a val='3' " + (a == b.getFullYear() && 3 == b.getMonth() ? "class='select'" : "") + " " + (a == e && 3 == f ? "class='current'" : "") + ">\u56db\u6708</a></td>";
        d += "</tr>";
        d += "<tr>";
        d += "<td><a val='4' " + (a == b.getFullYear() && 4 == b.getMonth() ? "class='select'" : "") + " " + (a == e && 4 == f ? "class='current'" : "") + ">\u4e94\u6708</a></td>";
        d += "<td><a val='5' " + (a == b.getFullYear() && 5 == b.getMonth() ? "class='select'" : "") + " " + (a == e && 5 == f ? "class='current'" : "") + ">\u516d\u6708</a></td>";
        d += "<td><a val='6' " + (a == b.getFullYear() && 6 == b.getMonth() ? "class='select'" : "") + " " + (a == e && 6 == f ? "class='current'" : "") + ">\u4e03\u6708</a></td>";
        d += "<td><a val='7' " + (a == b.getFullYear() && 7 == b.getMonth() ? "class='select'" : "") + " " + (a == e && 7 == f ? "class='current'" : "") + ">\u516b\u6708</a></td>";
        d += "</tr>";
        d += "<tr>";
        d += "<td><a val='8' " + (a == b.getFullYear() && 8 == b.getMonth() ? "class='select'" : "") + " " + (a == e && 8 == f ? "class='current'" : "") + ">\u4e5d\u6708</a></td>";
        d += "<td><a val='9' " + (a == b.getFullYear() && 9 == b.getMonth() ? "class='select'" : "") + " " + (a == e && 9 == f ? "class='current'" : "") + ">\u5341\u6708</a></td>";
        d += "<td><a val='10' " + (a == b.getFullYear() && 10 == b.getMonth() ? "class='select'" : "") + " " + (a == e && 10 == f ? "class='current'" : "") + ">\u5341\u4e00\u6708</a></td>";
        d += "<td><a val='11' " + (a == b.getFullYear() && 11 == b.getMonth() ? "class='select'" : "") + " " + (a == e && 11 == f ? "class='current'" : "") + ">\u5341\u4e8c\u6708</a></td>";
        d += "</tr>";
        d += "</table>";
        return d;
    }
    acts.GetYears = function getYears(a) {
        var today = new Date;
        var e = today.getFullYear();
        var f = today.getMonth();
        var q = today.getDate();
        a = Math.floor(a / 10) * 10;
        var d = acts.FormatInputValue();
        var h = "";
        var m = "";
        var o = "";
        args.complement || (o = "style='display:none'");
        var b = "<table class='tabY'>";
        for (var g = 0; g < 3; g++) {
            b += "<tr>";
            for (var i = 0; i < 4; i++) {
                m = h = "";
                if (g + 1 * i + 1 != 1 && (g + 1) * (i + 1) != 12) {
                    if (a == d.getFullYear()) h = "select";
                    if (a == e) m = "current";
                    b += "<td><a class='" + h + " " + m + "' >" + a + "</a></td>";
                    a++;
                } else if (g + 1 * i + 1 == 1) {
                    if (a - 1 == d.getFullYear()) h = "select";
                    if (a - 1 == e) m = "current";
                    b += "<td><a class='prevY " + h + " " + m + "' " + o + ">" + (a - 1) + "</a></td>";
                } else {
                    if (a == d.getFullYear()) h = "select";
                    if (a == e) m = "current";
                    b += "<td><a class='nextY " + h + " " + m + "' " + o + ">" + a + "</a></td>";
                }
            }
            b += "</tr>";
        }
        b += "</table>";
        return b;
    }
    acts.GetYearsRange = function getYearsRange(a) {
        var today = new Date;
        var e = today.getFullYear();
        var f = today.getMonth();
        var q = today.getDate();
        a = Math.floor(a / 100) * 100;
        var d = acts.FormatInputValue();
        var h = "";
        var m = "";
        var o = "";
        args.complement || (o = "style='display:none'");
        var b = "<table class='tabYS'>";
        for (var g = 0; g < 3; g++) {
            b += "<tr>";
            for (var i = 0; i < 4; i++) {
                m = h = "";
                if (g + 1 * i + 1 != 1 && (g + 1) * (i + 1) != 12) {
                    if (a <= d.getFullYear() && d.getFullYear() <= (a + 9)) h = "select";
                    if (a <= e && e <= (a + 9)) m = "current";
                    b += "<td><a class='" + h + " " + m + "' >" + a + '-<br />' + (a + 9) + "</a></td>";
                    a += 10;
                } else if (g + 1 * i + 1 == 1) {
                    if ((a - 10) <= d.getFullYear() && d.getFullYear() <= (a - 1)) h = "select";
                    if ((a - 10) <= e && e <= (a - 1)) m = "current";
                    b += "<td><a class='prevYS " + h + " " + m + "' " + o + ">" + (a - 10) + '-<br />' + (a - 1) + "</a></td>";
                } else {
                    if ((a + 10) <= d.getFullYear() && d.getFullYear() <= (a + 19)) h = "select";
                    if ((a + 10) <= e && e <= (a + 19)) m = "current";
                    b += "<td><a class='nextYS " + h + " " + m + "' " + o + ">" + (a + 10) + '-<br />' + (a + 19) + "</a></td>";
                }
            }
            b += "</tr>";
        }
        b += "</table>";
        return b;
    }
    acts.NextBtn = function nextBtn(a) {
        var b = $("#" + args.controlId).find(".reserve");
        var d = $("#" + args.controlId).find(".enabled");
        b.stop();
        d.stop();
        b.removeClass("reserve").addClass("enabled");
        d.removeClass("enabled").addClass("reserve");
        b.css({
            "margin-left": d.width() + "px",
            "margin-top": "0px"
        });
        b.empty().append(a);
        b.animate({
            "margin-left": "0px"
        },
		args.speed);
        d.animate({
            "margin-left": "-" + d.width() + "px"
        },
		args.speed,
		function () {
		    d.empty()
		})
    }
    acts.PreBtn = function preBtn(a) {
        var b = $("#" + args.controlId).find(".reserve");
        var d = $("#" + args.controlId).find(".enabled");
        b.stop();
        d.stop();
        b.removeClass("reserve").addClass("enabled");
        d.removeClass("enabled").addClass("reserve");
        b.css({
            "margin-left": "-" + d.width() + "px",
            "margin-top": "0px"
        });
        b.empty().append(a);
        b.animate({
            "margin-left": "0px"
        },
		args.speed);
        d.animate({
            "margin-left": d.width() + "px"
        },
		args.speed,
		function () {
		    d.empty()
		})
    }
    acts.SelectedYearOrMonth = function selectedYearOrMonth(a) {
        var b = $("#" + args.controlId).find(".reserve");
        var d = $("#" + args.controlId).find(".enabled");
        b.stop();
        d.stop();
        b.removeClass("reserve").addClass("enabled");
        d.removeClass("enabled").addClass("reserve");
        $("#" + args.controlId).css({
            "z-index": 1
        });
        b.css({
            "z-index": -1
        });
        d.css({
            "z-index": -1
        });
        b.css({
            "margin-left": "0px",
            "margin-top": d.height() + "px"
        });
        b.empty().append(a);
        b.animate({
            "margin-top": "0px"
        },
		args.speed);
        d.animate({
            "margin-top": "-" + d.width() + "px"
        },
		args.speed,
		function () {
		    d.empty();
		    $("#" + args.controlId).css({
		        "z-index": 0
		    });
		    b.css({
		        "z-index": 0
		    });
		    d.css({
		        "z-index": 0
		    })
		})
    }
    acts.ClickedCurrentText = function clickedCurrentText(a) {
        var b = $("#" + args.controlId).find(".reserve");
        var d = $("#" + args.controlId).find(".enabled");
        b.stop();
        d.stop();
        b.removeClass("reserve").addClass("enabled");
        d.removeClass("enabled").addClass("reserve");
        $("#" + args.controlId).css({
            "z-index": 1
        });
        b.css({
            "z-index": -1
        });
        d.css({
            "z-index": -1
        });
        b.css({
            "margin-left": "0px",
            "margin-top": "-" + d.height() + "px"
        });
        b.empty().append(a);
        b.animate({
            "margin-top": "0px"
        },
		args.speed);
        d.animate({
            "margin-top": d.width() + "px"
        },
		args.speed,
		function () {
		    d.empty();
		    $("#" + args.controlId).css({
		        "z-index": 0
		    });
		    b.css({
		        "z-index": 0
		    });
		    d.css({
		        "z-index": 0
		    })
		})
    }
    acts.ClickedToday = function clickedToday(a) {
        var b = $("#" + args.controlId).find(".reserve");
        var d = $("#" + args.controlId).find(".enabled");
        b.stop();
        d.stop();
        b.removeClass("reserve").addClass("enabled");
        d.removeClass("enabled").addClass("reserve");
        $("#" + args.controlId).css({
            "z-index": 1
        });
        b.css({
            "z-index": -1
        });
        d.css({
            "z-index": -1
        });
        b.css({
            "margin-left": "0px",
            "margin-top": d.height() + "px"
        });
        b.empty().append(a);
        b.animate({
            "margin-top": "0px"
        },
		args.speed);
        d.animate({
            "margin-top": "-" + d.width() + "px"
        },
		args.speed,
		function () {
		    d.empty();
		    $("#" + args.controlId).css({
		        "z-index": 0
		    });
		    b.css({
		        "z-index": 0
		    });
		    d.css({
		        "z-index": 0
		    })
		})
    }
    acts.FormatInputValue = function formatInputValue() {
        re = /(\d\d\d\d)(\W)?(\d\d)(\W)?(\d\d)/g;
        var parseReg = /[^0-9]+/g;
        var a = TBOX.val();
        var arr = ("" + a).split(parseReg);
        if (arr[arr.length - 1].replace(/\s/ig, '') == "") {
            arr.splice(arr.length - 1, 1);
        }
        if (arr.length == 1) {
            a = Number(arr[0]) + "-01-01";
        }
        else if (arr.length == 2) {
            a = Number(arr[0]) + "-" + (Number(arr[1]) >= 10 ? Number(arr[1]) : "0" + Number(arr[1])) + "-" + "01";
        }
        else if (arr.length >= 3) {
            a = Number(arr[0]) + "-" + (Number(arr[1]) >= 10 ? Number(arr[1]) : "0" + Number(arr[1])) + "-" + (Number(arr[2]) >= 10 ? Number(arr[2]) : "0" + Number(arr[2]));
            if (arr.length == 4) {
                time = " " + (Number(arr[3]) >= 10 ? Number(arr[3]) : '0' + Number(arr[3])) + ':' + '00:00';
            }
            else if (arr.length == 5) {
                time = " " + (Number(arr[3]) >= 10 ? Number(arr[3]) : '0' + Number(arr[3])) + ':' + (Number(arr[4]) >= 10 ? Number(arr[4]) : '0' + Number(arr[4])) + ':00';
            }
            else if (arr.length >= 6) {
                time = " " + (Number(arr[3]) >= 10 ? Number(arr[3]) : '0' + Number(arr[3])) + ':' + (Number(arr[4]) >= 10 ? Number(arr[4]) : '0' + Number(arr[4])) + ':' + (Number(arr[5]) >= 10 ? Number(arr[5]) : '0' + Number(arr[5]));
            }
        }
        a = a.replace(re, "$1/$3/$5@").split("@")[0];
        if (NeedTimes) {
            $('#' + _inputControlID + 'HourSELECT')[0].selectedIndex = Number(arr[3]);
            $('#' + _inputControlID + 'MinuteSELECT')[0].selectedIndex = Number(arr[4]);
        }
        return new Date(a);
    }
    acts.PosCalendar = function posCalendar(a) {
        var b = [];
        b.x = a.offsetLeft;
        for (b.y = a.offsetTop; a = a.offsetParent; ) {
            b.x += a.offsetLeft;
            b.y += a.offsetTop;
        }
        return b;
    }
    acts.Constructor = function () {
        var today = new Date;
        var e = today.getFullYear();
        var f = today.getMonth();
        var q = today.getDate();
        var k = "";
        k += "<div class='Calendar'>";
        k += "  <div id='" + args.controlId + "'class='calendar'>";
        k += "    <div class='calMain'>";
        k += "      <div class='calTitle'>";
        k += "        <a class='prev'></a><span class='t_date'><span class='currentText'>" + e + "\u5e74" + (f + 1) + "\u6708</span></span><a class='next'></a>";
        k += "      </div>";
        k += "      <div class='calContent'>";
        k += "        <div class='reserve'>";
        k += "        </div>";
        k += "        <div class='enabled'>";
        k += acts.GetDays(e, f);
        k += "        </div>";
        k += "      </div>";
        k += "      <div class='bottomContent'>";
        k += "        <div class='currentDate'>";
        k += "          <a class='currentDateText' title='转到今日'>今天</a>";
        k += "        </div>";
        k += "      </div>";
        k += "    </div>";
        k += "  </div>";
        k += "</div>";
        //$(TBOX).after(k);
        $(TBOX).before(k);
        $(TBOX).removeClass("TextBoxWidth90");
        $(TBOX).removeClass("TextBoxWidth95");
        $(TBOX).removeClass("TextBoxWidth200");
        $(TBOX).addClass("Calendar_inputBox");
        acts.SetDays();
    }
    acts.EventBind = function () {
        $("#" + args.controlId).find(".prev").mouseup(function () {
            var currentText = $("#" + args.controlId).find(".currentText");
            var text = $(currentText).text();
            if (text.indexOf('\u5e74') > 0 && text.indexOf('\u6708') > 0) {
                var y = Number(text.substring(0, text.indexOf('\u5e74')));
                var m = Number(text.substring(text.indexOf('\u5e74') + 1, text.indexOf('\u6708')));
                var d = acts.GetDays(y, m - 2);
                acts.PreBtn(d);
                if (m != 1) {
                    m -= 1;
                }
                else {
                    y -= 1;
                    m = 12;
                }
                $(currentText).text(y + '\u5e74' + m + '\u6708');
                acts.SetDays();
            } else if (text.indexOf('-') < 0) {
                var y = Number(text) - 1;
                d = acts.GetMonths(y);
                acts.PreBtn(d);
                acts.SetMonths();
                $(currentText).text(y);
            }
            else if (text.indexOf('-') > 0) {
                var startY = Number(text.substring(0, text.indexOf('-')));
                var endY = Number(text.substring(text.indexOf('-') + 1));
                if ((endY - startY) < 10) {
                    startY -= 10;
                    endY -= 10;
                    var d = acts.GetYears(startY);
                    acts.PreBtn(d);
                    acts.SetYears();
                    $(currentText).text(startY + '-' + endY);
                }
                else {
                    startY -= 100;
                    endY -= 100;
                    var d = acts.GetYearsRange(startY);
                    acts.PreBtn(d);
                    acts.SetYearsRange();
                    $(currentText).text(startY + '-' + endY);
                }
            }
        });
        $("#" + args.controlId).find(".next").mouseup(function () {
            var currentText = $("#" + args.controlId).find(".currentText");
            var text = $(currentText).text();
            if (text.indexOf('\u5e74') > 0 && text.indexOf('\u6708') > 0) {
                var y = Number(text.substring(0, text.indexOf('\u5e74')));
                var m = Number(text.substring(text.indexOf('\u5e74') + 1, text.indexOf('\u6708')));
                var d = acts.GetDays(y, m);
                acts.NextBtn(d);
                if (m != 12) {
                    m += 1;
                }
                else {
                    y += 1;
                    m = 1;
                }
                $(currentText).text(y + '\u5e74' + m + '\u6708');
                acts.SetDays();
            } else if (text.indexOf('-') < 0) {
                var y = Number(text) + 1;
                d = acts.GetMonths(y);
                acts.NextBtn(d);
                acts.SetMonths();
                $(currentText).text(y);
            } else if (text.indexOf('-') > 0) {
                var startY = Number(text.substring(0, text.indexOf('-')));
                var endY = Number(text.substring(text.indexOf('-') + 1));
                if ((endY - startY) < 10) {
                    startY += 10;
                    endY += 10;
                    var d = acts.GetYears(startY);
                    acts.NextBtn(d);
                    acts.SetYears();
                    $(currentText).text(startY + '-' + endY);
                }
                else {
                    startY += 100;
                    endY += 100;
                    var d = acts.GetYearsRange(startY);
                    acts.NextBtn(d);
                    acts.SetYearsRange();
                    $(currentText).text(startY + '-' + endY);
                }
            }
        });
        $("#" + args.controlId).find(".currentText").mouseup(function () {
            var text = $("#" + args.controlId).find(".currentText").text();
            if (text.indexOf('\u5e74') > 0 && text.indexOf('\u6708') > 0) {
                var y = Number(text.substring(0, text.indexOf('\u5e74')));
                var m = Number(text.substring(text.indexOf('\u5e74') + 1, text.indexOf('\u6708')));
                var a = acts.GetMonths(y);
                acts.ClickedCurrentText(a);
                acts.SetMonths();
                $("#" + args.controlId).find(".currentText").text(y);
            }
            else if (text.indexOf('-') < 0) {
                var y = Number(text);
                var a = acts.GetYears(y);
                acts.ClickedCurrentText(a);
                acts.SetYears();
                y = Math.floor(y / 10) * 10;
                $("#" + args.controlId).find(".currentText").text(y + "-" + (y + 9));
            }
            else {
                var startY = Number(text.substring(0, text.indexOf('-')));
                var endY = Number(text.substring(text.indexOf('-') + 1));
                if ((endY - startY) < 10) {
                    var a = acts.GetYearsRange(startY);
                    acts.ClickedCurrentText(a);
                    acts.SetYearsRange();
                    startY = Math.floor(startY / 100) * 100;
                    $("#" + args.controlId).find(".currentText").text(startY + "-" + (startY + 99));
                }
            }
        });
        $("#" + args.controlId).find('.currentDateText').mouseup(function () {
            var d = new Date();

            var text = $("#" + args.controlId).find(".currentText").text();
            var y = Number(text.substring(0, text.indexOf('\u5e74')));
            var m = Number(text.substring(text.indexOf('\u5e74') + 1, text.indexOf('\u6708')));
            if (y == d.getFullYear() && m == d.getMonth() + 1) return;

            var t = acts.GetDays(d.getFullYear(), d.getMonth());
            acts.ClickedToday(t);
            acts.SetDays();
            $("#" + args.controlId).find(".currentText").text(d.getFullYear() + '\u5e74' + (d.getMonth() + 1) + '\u6708');
        });
        TBOX.bind("click focus",
		function () {
		    if ($("#" + args.controlId + ":hidden").length != 0) {
		        $(".calendar").hide();
		        var a = $("#" + args.controlId);
		        var b = acts.PosCalendar(TBOX[0]);
		        var d = b.x + Number(TBOX.attr("clientLeft")) + 2;
		        b = b.y + Number(TBOX.attr("clientTop")) + Number(TBOX.attr("clientHeight")) - 1;
		        //		        a.css({
		        //		            top: b + "px",
		        //		            left: d + "px"
		        //		        });
		        a.css({
		            marginTop: "20px",
		            position: "absolute"
		        });
		        d = $("#" + args.controlId).width();
		        b = $("#" + args.controlId).height();
		        a.width(0);
		        a.height(0);
		        a.show().animate({
		            width: d + "px",
		            height: b + "px"
		        },
				args.speed);
		        a.bind("selectstart",
				function () {
				    return false;
				}).bind("mousedown",
				function () {
				    return false;
				})
		    }
		});
        if (!args.readonly) {
            TBOX.bind("keyup",
			function () {
			    var text = TBOX.val();
			    var parseReg = /[^0-9]+/g;
			    var arr = ("" + text).split(parseReg);
			    if (arr[arr.length - 1].replace(/\s/ig, '') == "") {
			        arr.splice(arr.length - 1, 1);
			    }
			    if (arr.length !== 0) {
			        if (arr.length >= 1 && (Number(arr[0] < 1000) || Number(arr[0] >= 10000))) return;
			        if (arr.length >= 2 && Number(arr[1]) > 12) {
			            alert('月份值输入错误!');
			            return;
			        }
			        if (arr.length >= 3 && Number(arr[2]) > 31) {
			            alert('日期值输入错误!');
			            return;
			        }
			        if (arr.length >= 4 && Number(arr[3]) > 23) {
			            alert('时间值输入错误!');
			            return;
			        }
			        if (arr.length >= 5 && Number(arr[4]) > 59) {
			            alert('分钟值输入错误!');
			            return;
			        }
			        if (arr.length >= 6 && Number(arr[5]) > 59) {
			            alert('秒数值输入错误!');
			            return;
			        }
			        if (arr.length == 1) {
			            var y = Number(arr[0]);
			            var a = acts.GetYears(y);
			            acts.ClickedCurrentText(a);
			            acts.SetYears();
			            y = Math.floor(y / 10) * 10;
			            $("#" + args.controlId).find(".currentText").text(y + "-" + (y + 9));
			        }
			        else if (arr.length == 2) {
			            var y = Number(arr[0]);
			            var m = Number(arr[1]);
			            var a = acts.GetMonths(y);
			            acts.ClickedCurrentText(a);
			            acts.SetMonths();
			            $("#" + args.controlId).find(".currentText").text(y);
			        }
			        else if (arr.length >= 3) {
			            var od = acts.FormatInputValue();
			            var t = acts.GetDays(od.getFullYear(), od.getMonth());
			            acts.ClickedCurrentText(t);
			            acts.SetDays();
			            $("#" + args.controlId).find(".currentText").text(od.getFullYear() + '\u5e74' + (od.getMonth() + 1) + '\u6708');
			        }
			    }
			});
        }
        $(document).mouseup(function (a) {
            if ($(a.target).attr("id") != TBOX.attr("id") && ($(a.target).parentsUntil("#" + args.controlId).parent().length == 0 || $(a.target).parentsUntil("#" + args.controlId).parent()[0].id != args.controlId)) {
                $("#" + args.controlId).hide();
            }
        })


    }

    acts.AddTimeDropList = function () {
        //        var second = "";
        //        second += "<SELECT id='" + _inputControlID + "SecondSELECT' >";
        //        for (var i = 0; i < 60; i++) {
        //            second += "       <option value=''>" + (i < 10 ? "0" + i : i) + "</option>";
        //        }
        //        second += "</SELECT>秒";
        //        $(TBOX).after(second);
        var minute = "";
        minute += "<SELECT id='" + _inputControlID + "MinuteSELECT' >";
        for (var i = 0; i < 60; i++) {
            minute += "       <option value=''>" + (i < 10 ? "0" + i : i) + "</option>";
        }
        minute += "</SELECT>";
        $(TBOX).after(minute);
        var hours = "";
        hours += "<SELECT id='" + _inputControlID + "HourSELECT' >";
        for (var i = 0; i < 24; i++) {
            hours += "       <option value=''>" + (i < 10 ? "0" + i : i) + "</option>";
        }
        hours += "</SELECT>";
        $(TBOX).after(hours);

        $('#' + _inputControlID + 'HourSELECT').bind("change", acts.SetHMS);
        $('#' + _inputControlID + 'MinuteSELECT').bind("change", acts.SetHMS);
        //        $('#' + _inputControlID + 'SecondSELECT').bind("change", acts.SetHMS);

    }
    acts.SetHMS = function () {
        var a = TBOX.val();
        if (a == null || a.replace(/\s/ig, '') == "" || a.length < 10) {
            alert("请选择日期!");
            this.selectedIndex = 0;
            return;
        }
        a = a.substring(0, 10);

        TBOX.val(a + " " + acts.GetHMS());
    }
    acts.GetHMS = function () {
        var Hour = $('#' + _inputControlID + 'HourSELECT');
        var Minute = $('#' + _inputControlID + 'MinuteSELECT');
        //var Second = $('#' + _inputControlID + 'SecondSELECT');

        var h = parseInt(Hour[0].selectedIndex) < 10 ? "0" + Hour[0].selectedIndex : Hour[0].selectedIndex;
        var m = parseInt(Minute[0].selectedIndex) < 10 ? "0" + Minute[0].selectedIndex : Minute[0].selectedIndex;
        //var s = parseInt(Second[0].selectedIndex) < 10 ? "0" + Second[0].selectedIndex : Second[0].selectedIndex;
        return h + ":" + m + ":00";
    }

    acts.Init();
}